package com.http.controller;

import com.http.config.Result;
import com.http.intg.AsyncHttpServiceClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @ClassName: AsyncRestHttpController
 * @Description: AsyncRestHttp异步操作接口
 * @author: QT
 * @date: 2021年06月26日 下午17:30:00
 */
@Api(tags = "AsyncRestHttpController", description = "AsyncRestHttp操作接口")
@RestController
@RequestMapping("/asyncresthttp")
public class AsyncRestHttpController {
    public static final Logger log = LoggerFactory.getLogger(AsyncRestHttpController.class);

    @Autowired
    AsyncHttpServiceClient asyncHttpServiceClient;

    @ApiOperation("按员工ID获取员工列表")
    @GetMapping("/queryUserById")
    public @ResponseBody
    Result queryUserById(@ApiParam(name = "id", value = "用户ID", required = true)
                         @RequestParam int id) throws IOException {
        try{
            String username = asyncHttpServiceClient.getUserById(id);
            log.info("按员工ID获取员工："+username);
            return Result.succResult(username);
        }catch(IOException e){
            log.info("Exception: "+e);
            return Result.failResult("Exception: "+e);
        }
    }
}
